package com.Algorithm.HUAWEI.two20220303;

import java.util.HashSet;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/03/09/16:57
 * @Description:
 * @Target:
 */
public class 密码验证合格程序 {
/*
        * 密码要求:

        1.长度超过8位

        2.包括大小写字母.数字.其它符号,以上四种至少三种
        * [a,z]     [A,Z]    0-9       other
        *[97,122]   [65,90]   [48,57]

        3.不能有长度大于2的不含公共元素的子串重复 （注：其他符号不含空格或换行）

        数据范围：输入的字符串长度满足 1 \le n \le 100 \1≤n≤100
        输入描述：
*
*
* */


    // 2的思路,一个个遍历,用一个set,如果[a,z] add a,[A,Z] add A,0-9 add 0, other add o,最后返回set长度,用数组也可以[0,0,0,0]

    // 3的思路，set存，然后最后如果set少了3位以上，用少去的元素截取其中的三位来进行遍历寻找
    // 或者遍历的时候发现连续重复
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            if (dealWith(in.nextLine())){
                System.out.println("OK");
            }else {
                System.out.println("NG");
            }
        }



    }


    static boolean dealWith(String ss){
        boolean flag = true;
        if (ss.length()<=8){
            flag = false;
        }else {
            int[] ints = new int[4];
            HashSet set = new HashSet();
            StringBuffer stringBuffer = new StringBuffer();
//        [0,0,0,0]  [a,z] add a,[A,Z] add A,0-9 add 0, other add o
            for (int i = 0; i < ss.length(); i++) {
                if (set.contains(ss.charAt(i))){
                    stringBuffer.append(ss.charAt(i));
                }else {
                    set.add(ss.charAt(i));
                    if (checkQuJian(ss.charAt(i),97,122)){
                        ints[0]++;
                    }else if (checkQuJian(ss.charAt(i),65,90)){
                        ints[1]++;
                    }else if (checkQuJian(ss.charAt(i),48,57)){
                        ints[2]++;
                    }else {
                        ints[3]++;
                    }
                }


            }

            int count = 0;
            for (int i = 0; i < ints.length; i++) {
                if (ints[i]==0){
                    count++;
                }
            }

            if (count>1){
                flag = false;
                count = 0;
            }else {
                count = 0;
            }



           if (stringBuffer.length()>=3){
                for (int i = 0; i < stringBuffer.length()-3; i++) {
                    for (int j = 0; j < ss.length()-3; j++) {
                        if (ss.substring(j,j+3).equals(stringBuffer.toString().substring(i,i+3))){
                            count++;
                            System.out.println(ss.substring(j,j+3));
                        }
                    }
                    if (count<2){
                        count = 0;
                    }
                }
            }


            if (count>1){
                flag = false;
            }

        }





        return flag;
    }


    static boolean checkQuJian(int x,int a,int b){
        boolean flag = true;
        if (x<a){
            flag = false;
        }else if (x>b){
            flag = false;
        }
        return flag;
    }

}
